//
//  StatusCellTopView.swift
//  JLWeibo
//
//  Created by sunjinliang on 15/12/10.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
let iconViewWidth = 35
class StatusCellTopView: UIView {

    var  statusView : StatusViewModel?{
        didSet{
            iconView.sd_setImageWithURL(statusView?.userProfileUrl, placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = statusView?.status.user?.screen_name
            vipView.image = statusView?.userMemberImage
            verifiedView.image = statusView?.userVipImage
        }
    }
    /// 用户头像
    private lazy var iconView = UIImageView(image: UIImage(named: "avatar_default_big"))
    /// 用户姓名
    private lazy var nameLabel = UILabel(text1: "用户姓名", fontSize: 14)
    /// vip
    private lazy var vipView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    /// 时间
    private lazy var timeLabel = UILabel(text1: "刚刚", color: UIColor.orangeColor(), fontSize: 12)
    /// 来源
    private lazy var sourseLabel = UILabel(text1: "来自 黑马微博", fontSize: 12)
    /// 认证
    private lazy var verifiedView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
/// 给各个子控件添加约束
    func setupUI(){
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourseLabel)
        addSubview(verifiedView)
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(statusCellMargin)
            make.top.equalTo(self.snp_top).offset(statusCellMargin)
            make.width.equalTo(iconViewWidth)
            make.height.equalTo(iconViewWidth)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.top.equalTo(iconView.snp_top)
        }
        vipView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(statusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
            
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        sourseLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(statusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        verifiedView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
    }
  
}
